package com.yx.fmmall.service.impl;

import com.yx.fmmall.dao.PersonManagerDao;
import com.yx.fmmall.entity.PersonManager;
import com.yx.fmmall.service.PersonManagerService;
import com.yx.fmmall.vo.ResultVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Classname PersonManagerServiceImpl
 * @Date 2022/01/04 22:44
 * @Author by yx
 * @Description :
 */
@Service
public class PersonManagerServiceImpl implements PersonManagerService {

    @Resource
    private PersonManagerDao personManagerDao;

    @Override
    public ResultVO checkLogin(String name, String password) {
        // 1.根据账号查询用户信息
        PersonManager personManager = personManagerDao.getPersonManagerByName(name);
        // 2.判断
        if (personManager == null) {
            return new ResultVO(10001, "用户名不存在", null);
        } else {
            // 3.对输入的密码进行加密并比对
            // 使用加密后的密码与数据库中的密码进行比对
            if (personManager.getPassword().equals(password)) {
                // 验证成功
                return new ResultVO(10000, "登录成功", personManager);
            } else {
                // 密码错误
                return new ResultVO(10001, "密码错误", null);
            }
        }
    }
}
